<%@page import="java.util.*"%>
<%@ page import="com.shop.servlet.GoodTypeServlet" %>
<%@ page import="com.shop.servlet.impl.GoodTypeServletImpl" %>
<%@ page import="com.shop.entity.GoodType" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="com.shop.entity.Goods" %>
<%@ page import="com.shop.servlet.GoodsServlet" %>
<%@ page import="com.shop.servlet.impl.GoodsServletImpl" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String path = request.getContextPath();
	String basePath = request.getScheme()+"://" +request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	GoodTypeServlet servlet = new GoodTypeServletImpl();
	GoodsServlet servlet1 = new GoodsServletImpl();
	List<GoodType> goodTypes = servlet.selectAll();
	String s = JSON.toJSONString(goodTypes);
	String id = request.getParameter("id");
	Goods goods = new Goods();
	goods.setId(Integer.parseInt(id));
	goods = servlet1.selectOne(goods);

	request.setAttribute("goods",goods);
	request.setAttribute("s",s);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/backstyle.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript">
		var goodsType = ${s}
		$(function (){
			for (var item of goodsType) {
				if (item.pid =="-1"){
					var lit =new Option(item.typename,item.id)
					$("#type1").append(lit)
				}
			}
			function dochange(){
				$("#type2").children().remove()
				$("#type2").append(new Option("请选择",""))
				var id = $("#type1").val()
				for (var item of goodsType) {
					if (item.pid == id){
						var lit =new Option(item.typename,item.id)
						$("#type2").append(lit)
					}
				}
			}
			$("#type1").change(function () {
				dochange();
			})
			$("#type1").val(${goods.type1})
			dochange()
			$("#type2").val(${goods.type2})
		})
	</script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">表单</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>修改商品信息</span></div>
		<form method="get" action="/goods/update" enctype="multipart/form-data">
			<ul class="forminfo">
				<li><input name="id" value="${goods.id}"/></li>
				<li><label>商品名称</label><input name="gname" value="${goods.gname}" type="text" class="dfinput" /><i>标题不能超过30个字符</i></li>
				<li><label>所属大类</label>
					<select name="type1" id="type1">
						<option value="">无</option>
					</select>
				</li>
				<li><label>所属小类</label>
					<select name="type2" id="type2">
						<option value="">无</option>
					</select>
				</li>
				<li><label>商品图片</label><input name="pnguri" type="file" /></li>
				<li><label>商品价格</label><input name="price" type="text" class="dfinput" value="${goods.price}"/></li>
				<li><label>商品库存</label><input name="stock" type="text" class="dfinput" value="${goods.stock}"/></li>
				<li><label>商品描述</label><textarea rows="8" cols="40" name="des" >${goods.des}</textarea></li>
				<li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认保存"/></li>
			</ul>
		</form>
    </div>
<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div>
</body>
</html>

